import { Column, Entity, ManyToOne, Index } from 'typeorm';
import { BaseEntity } from '../../../common/entities/base.entity';
import { MasterCategory } from './master-category.entity';

export enum SiteMappingStatus {
  DISABLED = 0,
  ACTIVE = 1,
}

@Entity('site_category_maps')
@Index(['site', 'siteCategory'], { unique: true })
export class SiteCategoryMap extends BaseEntity {
  @Column({ type: 'varchar', length: 20, comment: '站点名称' })
  site: string;

  @Column({ type: 'varchar', length: 50, comment: '源站分类名' })
  siteCategory: string;

  @Column({ type: 'tinyint', comment: '母分类ID' })
  masterId: number;

  @Column({
    type: 'tinyint',
    default: SiteMappingStatus.ACTIVE,
    comment: '状态: 0-禁用 1-启用',
  })
  status: SiteMappingStatus;

  @Column({ type: 'text', nullable: true, comment: '映射说明' })
  description?: string;

  // 关联关系
  @ManyToOne(() => MasterCategory, (master) => master.siteMappings)
  masterCategory: MasterCategory;
}